// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   LinkedCaseInsensitiveMap.java

package org.springframework.util;

import java.util.*;

public class LinkedCaseInsensitiveMap extends LinkedHashMap
{

	private final Map caseInsensitiveKeys;
	private final Locale locale;

	public LinkedCaseInsensitiveMap()
	{
		this(((Locale) (null)));
	}

	public LinkedCaseInsensitiveMap(Locale locale)
	{
		caseInsensitiveKeys = new HashMap();
		this.locale = locale == null ? Locale.getDefault() : locale;
	}

	public LinkedCaseInsensitiveMap(int initialCapacity)
	{
		this(initialCapacity, null);
	}

	public LinkedCaseInsensitiveMap(int initialCapacity, Locale locale)
	{
		super(initialCapacity);
		caseInsensitiveKeys = new HashMap(initialCapacity);
		this.locale = locale == null ? Locale.getDefault() : locale;
	}

	public Object put(String key, Object value)
	{
		String oldKey = (String)caseInsensitiveKeys.put(convertKey(key), key);
		if (oldKey != null && !oldKey.equals(key))
			super.remove(oldKey);
		return super.put(key, value);
	}

	public void putAll(Map map)
	{
		if (map.isEmpty())
			return;
		java.util.Map.Entry entry;
		for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext(); put((String)entry.getKey(), entry.getValue()))
			entry = (java.util.Map.Entry)iterator.next();

	}

	public boolean containsKey(Object key)
	{
		return (key instanceof String) && caseInsensitiveKeys.containsKey(convertKey((String)key));
	}

	public Object get(Object key)
	{
		if (key instanceof String)
			return super.get(caseInsensitiveKeys.get(convertKey((String)key)));
		else
			return null;
	}

	public Object remove(Object key)
	{
		if (key instanceof String)
			return super.remove(caseInsensitiveKeys.remove(convertKey((String)key)));
		else
			return null;
	}

	public void clear()
	{
		caseInsensitiveKeys.clear();
		super.clear();
	}

	protected String convertKey(String key)
	{
		return key.toLowerCase(locale);
	}

	public volatile Object put(Object obj, Object obj1)
	{
		return put((String)obj, obj1);
	}
}
